﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace LiUTrading.Models
{
    public class UserRepository
    {
         private LiuTradingDBEntities entities = new LiuTradingDBEntities();

        //Query Methods
        public IQueryable<User> FindAllUsers(){
            
            return entities.Users;   
        }
        /*public IQueryable<User> FindAllBookAds()
        {
            return from ad in entities.Ads
                   where ad.Category == "Books"
                   orderby ad.DateTime
                   select ad;
        }*/

        public User GetUser(int id){
            return entities.Users.FirstOrDefault(u => u.UserId == id);
        }

        public User GetUser(string liuId)
        {
            return entities.Users.FirstOrDefault(u=>u.LiuID== liuId);
        }
        //Insert/delete
        public void Add(User user)
        {
            entities.Users.AddObject(user);
        }

        public void Delete(User user)
        {
            entities.Users.DeleteObject(user);
        }

        public void Save()
        {
            entities.SaveChanges();
        }
    
    }
}